var ctx;

var mkey = "";
var bkey = "";


function setCtx(ctx){
	this.ctx = ctx;
}

//新增或编辑菜单(1:新增 2:编辑)
var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
function saveOrUpdateBtn (){
	var btnId = 0;
	if($("#btnId").val() != 0 && $("#btnId").val() != null){
		btnId = $("#btnId").val();
	}
	var mName = $("#menuName").val();
	var name = $("#name").val();
	var bvalue = $("#bvalue").val();
	var memo = $("#memo").val();
	
	//解决ie9以下placeholder与value重复的问题
	if(mName == $("#menuName").attr("placeholder")){
		mName = "";
	}
	if(name == $("#name").attr("placeholder")){
		name = "";
	}
	if(bvalue == $("#bvalue").attr("placeholder")){
		bvalue = "";
	}
	if(memo == $("#memo").attr("placeholder")){
		memo = "";
	}
	
	var index1 = layer.load(1);
	$.post(ctx+"/button/editBtn",
		{
			mkey:mName,
			bkey:name,
			bvalue:bvalue,
			id:btnId,
			memo:memo
		},function(data){
			data = JSON.parse(data);
			if(data.success){
				layer.msg("操作成功",{
					icon: 1,
					time: 1000 //2秒关闭（如果不配置，默认是3秒）
				},function(){
					parent.loadContent("/button/btnList");
					parent.layer.close(index); //根据窗口索引关闭窗口   
				});
			} else {
				layer.close(index1);
				layer.msg(data.msg,{
					icon: 2,
					time: 1000 //2秒关闭（如果不配置，默认是3秒）
				},function(){
					parent.layer.close(index); //根据窗口索引关闭窗口   
				});
			}
		});
}
